package it.unina.uninachi;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class ImageAdapter extends BaseAdapter {
    private Context mContext;
    private int risoluzione;

    public ImageAdapter(Context c, int r) {
        mContext = c;
        risoluzione = r;
    }

    public int getCount() {
        return mThumbIds.length;
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    //creo una nuova ImageView per ogni elemento referenziato dall'adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  //inizializzazione attributi
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(risoluzione,risoluzione));
            imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            imageView.setPadding(0, 0, 0, 0);
        } else {
            imageView = (ImageView) convertView;
        }

        imageView.setImageResource(mThumbIds[position]);
        return imageView;
    }

    //riferimenti alle immagini
    private Integer[] mThumbIds = {
    		R.drawable.alex, R.drawable.alfred, R.drawable.anita, R.drawable.anne,
    		R.drawable.bernard, R.drawable.bill, R.drawable.charles, R.drawable.claire,
    		R.drawable.david, R.drawable.eric, R.drawable.frans, R.drawable.george,
    		R.drawable.herman, R.drawable.joe, R.drawable.maria, R.drawable.max,
    		R.drawable.paul, R.drawable.peter, R.drawable.philip, R.drawable.richard, R.drawable.robert,
    		R.drawable.sam, R.drawable.susan, R.drawable.tom
    };
}